package UMC.Web.UI;

import UMC.Web.UICell;
import UMC.Web.UIEventText;
import UMC.Web.WebMeta;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

public class UITextItems extends UICell {

    List<UIEventText> items = new LinkedList<>();

    public UITextItems() {
        this.data = new WebMeta().put("data", this.items);
    }

    public UITextItems(String model, String cmd) {
        this.data = new WebMeta().put("model", model, "cmd", cmd).put("data", this.items);

    }

    public UITextItems(String model, String cmd, String value) {
        this.data = new WebMeta().put("model", model, "cmd", cmd, "search", value).put("data", this.items);

    }

    public UITextItems(String model, String cmd, WebMeta value) {
        this.data = new WebMeta().put("model", model, "cmd", cmd).put("search", value).put("data", this.items);

    }

    public UITextItems event(String key) {
        this.data.put("event", key);
        return this;
    }

    public UITextItems add(UIEventText item) {
        this.items.add(item);
        return this;
    }

    public UITextItems msg(String msg) {
        this.data.put("msg", msg);
        return this;
    }

    public UITextItems add(UIEventText... items) {
        this.items.addAll(Arrays.asList(items));
        return this;
    }

    public int size() {
        return this.data.size();

    }

    private WebMeta data;

    @Override
     public WebMeta data() {
        return data;
    }

    @Override
    public String type() {
        return "TextItems";
    }

}